import { ADMIN_ROLE_NAME } from '@/constants';
import { ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-form';
import { Form } from 'antd';

export default (props: { tenant?: TenantEntity }) => {
  const { tenant } = props;

  if (!tenant) return null;

  return (
    <>
      <Form.Item noStyle shouldUpdate>
        {(form) => {
          if (form.getFieldValue('name') === ADMIN_ROLE_NAME) return null;
          return (
            <ProFormText
              name="name"
              label="名称"
              rules={[{ required: true, message: '请填写名称' }]}
            />
          );
        }}
      </Form.Item>
      <ProFormSelect
        name="nodes"
        label="节点"
        rules={[{ required: true, message: '请选择节点' }]}
        mode={'multiple'}
        options={tenant.allow_nodes.split(',').map((node) => ({ label: node, value: node }))}
      />
      <ProFormDigit
        label={`最大CPU(核)(1 ~ ${tenant.max_cpu})`}
        name="max_cpu"
        min={1}
        max={tenant.max_cpu}
        dataFormat="string"
        rules={[{ required: true, message: '请填入最大CPU' }]}
      />

      <ProFormDigit
        label={`最大内存(G)(1 ~ ${tenant.max_memory})`}
        name="max_memory"
        min={1}
        max={tenant.max_memory}
        rules={[{ required: true, message: '请填入最大内存' }]}
      />

      <ProFormDigit
        label={`最大硬盘(G)(1 ~ ${tenant.max_disk})`}
        name="max_disk"
        min={1}
        max={tenant.max_disk}
        rules={[{ required: true, message: '请填入最大硬盘' }]}
      />
    </>
  );
};
